﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using System.Windows.Forms;

namespace BLVJX
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();

            comboBox_接口.SelectedIndex = 0;
        }

        private void button_解析_Click(object sender, EventArgs e)
        {
            try
            {
                string url = $"https://www.wannengjiexi.com/jiexi{comboBox_接口.SelectedIndex + 1}/?url={textBox_地址.Text.Trim()}";
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Timeout = 5000;
                request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36";
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader stringReader = new StreamReader(response.GetResponseStream());
                string html = stringReader.ReadToEnd();
                richTextBox_解析结果.Text = html;
                string pattern = "<iframe id=\"baiyug\" scrolling=\"no\" src=\"";
                Match match = Regex.Match(html, pattern);
                int left = match.Index + pattern.Length;
                int right = html.IndexOf("\"", left + 1);
                string src = html.Substring(left, right - left);
                Process.Start(src);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
